package com.itheima.entry.service.impl;

import com.itheima.entry.dao.IStudentDAO;
import com.itheima.entry.domain.Student;
import com.itheima.entry.factory.StudentFactroy;
import com.itheima.entry.service.IStudentService;

import java.util.ArrayList;

public class StudentServiceImpl extends StudentFactroy implements IStudentService {

    private static IStudentDAO dao = StudentFactroy.getDao();

    //增
    @Override
    public void add(Student st) {
        dao.add(st);
    }

    //删
    @Override
    public void remove(String id) {
        dao.remove(id);

    }

    //修改
    @Override
    public void update(Student st) {
        dao.update(st);

    }

    //判断id是否存在
    @Override
    public boolean isExists(String id) {
        ArrayList<Student> list = dao.allStudents();

        if( list.stream().filter(s->s.getId().equals(id)).count()==0){
            return false;
        }
        return true;
    }

    //查询所有学生
    @Override
    public ArrayList<Student> allStudents() {
        return dao.allStudents();
    }

    //通过名字搜索学生
    @Override
    public ArrayList<Student> sameNameStudents(String name) {
        return dao.sameNameStudents(name);
    }

    //通过手机搜索学生
    @Override
    public ArrayList<Student> phoneToStudent(String phone) {
        return dao.phoneToStudent(phone);
    }


}
